package posthttp;

import com.alibaba.fastjson.JSON;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author chaird
 * @create 2022-03-02 22:10
 */
public class App2 {

  public static void main(String[] args) throws Exception {

    Scanner scanner = new Scanner(System.in);
    while (true) {
      System.out.println("-----------开始---------------------");
      String mobile = scanner.nextLine();

      // json格式的参数，我们可以用map来封装参数，然后将参数转换为json格式
      Map<String, Object> params = new HashMap<>();
      params.put("mobile", mobile);
      // 对方的ID
      params.put("code", "0086");
      // 自己的ID
      params.put("type", "0");
      String paramsJson = JSON.toJSONString(params); // 将参数转换为json字符串
      //System.out.println(paramsJson);

      HttpClient client = new HttpClient(); // 客户端实例化
      PostMethod postMethod =
          new PostMethod(
              "https://passport.csdn.net/v1/register/pc/sendVerifyCode"); // 请求方法post，可以将请求路径传入构造参数中
      postMethod.addRequestHeader("Content-type", "application/json; charset=utf-8");
      postMethod.addRequestHeader("Accept", "application/json, text/plain, */*");
      postMethod.addRequestHeader(":path", "/interact/wrapper/pc/fans/v1/api/follow");
      postMethod.addRequestHeader(":scheme", "https");
      postMethod.addRequestHeader("accept", "application/json, text/plain, */*");
      postMethod.addRequestHeader("origin", "https://csp1999.blog.csdn.net");
      postMethod.addRequestHeader("referer", "https://csp1999.blog.csdn.net/?type=blog");
      postMethod.addRequestHeader(
          "user-agent",
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36");
      String cookie =
          "uuid_tt_dd=10_36835853870-1646316686824-562811; dc_session_id=10_1646316686824.749343; c_first_ref=default; c_first_page=https://cbeann.blog.csdn.net/; c_segment=11; dc_sid=4467d465666aa5fc27bfaa28a59b8fb1; hide_login=1; acw_tc=276077e016463166888206713e476198d217f3e22afa8c6209df3006d250a0; SESSION=a1ab92fa-4669-4f9f-91e9-7ad3d52e5517; _uab_collina=164631669029484150315067; acw_sc__v3=6220cc96b4ddca330a234352cb8b6f6457fabfda; acw_sc__v2=6220cca6ee00fad79bb5693bb9a7bdb8e5ab9167; UN=ahhha00; BT=1646316750026; p_uid=U010000; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1646316689,1646316713; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_36835853870-1646316686824-562811!5744*1*ahhha00; firstDie=1; c_pref=https://cbeann.blog.csdn.net/; c_ref=https://cbeann.blog.csdn.net/?type=blog; c_page_id=default; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac={\"islogin\":{\"value\":\"1\",\"scope\":1},\"isonline\":{\"value\":\"0\",\"scope\":1},\"isvip\":{\"value\":\"0\",\"scope\":1},\"uid_\":{\"value\":\"ahhha00\",\"scope\":1}}; dc_tos=r86a3x; log_Id_pv=5; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1646316718; log_Id_click=7; ssxmod_itna=eqUx9DRieDqqnlDzZKRhgODuGoP4=oG8D0xYvdD/KKpDnqD=GFDK40oEgvbKoeKYK2AexaqyCOnKqf3phP0=fYGDh3K7XBq0aDbqGkkiChQGGUxBYDQxAYDGDDPDoxKD1D3qDkD7g1ZlndtDm4GWzqGfDDoDYS6nDitD4qDB+2dDKqGgzwqKzwrXGeNQ6kqK57GyD0t=xBLrCZT3s=FKlw2TT1KeQDDHDRyxC0H4trh4ao=DzkODtTNl/qQQZatDyL0sziPeI05e3heFSDp57GEof7G2tBCs9Bmb3OE4RB4ol2+xDDfh60DmiDD=; ssxmod_itna2=eqUx9DRieDqqnlDzZKRhgODuGoP4=oG8D0xY5G9brKrDBk77lx7Pmxm8t47GFKWdBN1xylRvt15x3lKR=yf2CBumtOFCSdKtVP1oRGqPHLdaEs2F9YM6HoyQQCL98y61uBGsLj9qy/Ojy4SQAbu=n9k6UILiLn2iZj80jFM3p3LdDk8T=ElRxhxX/QMobrL2NT1vRnxibglrFalNUlSTqU=U3TQ0NpPHWV1bF5=WCd/HbPeOz1KbvnpgaVl75=puYxc0hoayt6=lG2LONq5x71feG69Hb5oy9rs/52YPDKTKO+ELT0rYwGD4Os2YYVkQ4jKeBYqAdpAeKBKN7ogG1RAKiW+ET5dAs4x4Ggsy7qeYz7nhNimSiGD7=DYKqBbe70DB4K87oDnDzDqeD===";
      postMethod.addRequestHeader("cookie", cookie);

      byte[] requestBytes = paramsJson.getBytes("utf-8"); // 将参数转为二进制流
      InputStream inputStream = new ByteArrayInputStream(requestBytes, 0, requestBytes.length);
      RequestEntity requestEntity =
          new InputStreamRequestEntity(
              inputStream, requestBytes.length, "application/json; charset=utf-8"); // 请求体
      postMethod.setRequestEntity(requestEntity); // 将参数放入请求体

      int i = client.executeMethod(postMethod); // 执行方法
      System.out.println("请求状态" + i);
      // 这里因该有判断的，根据请求状态判断请求是否成功，然后根据第三方接口返回的数据格式，解析出我们需要的数据

      byte[] responseBody = postMethod.getResponseBody(); // 得到相应数据
      String s = new String(responseBody);
      System.out.println(s);
      System.out.println("-----------结束---------------------");
    }
  }
}
